package com.ibeeking.found.cms.c.rest.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;
import com.ibeeking.found.cms.api.common.dto.ArticleDTO;
import com.ibeeking.found.cms.api.common.dto.ArticleGroupDTO;
import com.ibeeking.found.cms.api.common.dto.CampaignGoodsDTO;
import com.ibeeking.found.cms.api.common.dto.CampaignInfoDTO;
import com.ibeeking.found.cms.api.common.dto.CampaignLowPriceDTO;
import com.ibeeking.found.cms.api.common.dto.CampaignPageDTO;
import com.ibeeking.found.cms.api.common.dto.CmsShopModuleInfoDTO;
import com.ibeeking.found.cms.api.common.dto.CouponInfoDTO;
import com.ibeeking.found.cms.api.common.dto.CouponInfoPageDTO;
import com.ibeeking.found.cms.api.common.dto.GoodsCategoryDTO;
import com.ibeeking.found.cms.api.common.dto.GoodsDTO;
import com.ibeeking.found.cms.api.common.dto.GoodsGroupBaseDTO;
import com.ibeeking.found.cms.api.common.dto.GoodsVoDTO;
import com.ibeeking.found.cms.api.common.query.ArticleGroupQuery;
import com.ibeeking.found.cms.api.common.query.ArticleQuery;
import com.ibeeking.found.cms.api.common.query.CampaignLowPriceFeignQuery;
import com.ibeeking.found.cms.api.common.query.CampaignPageListQuery;
import com.ibeeking.found.cms.api.common.query.CouponInfoPageQuery;
import com.ibeeking.found.cms.api.common.query.FeignCampaignQuery;
import com.ibeeking.found.cms.api.common.query.GoodsByGroupQuery;
import com.ibeeking.found.cms.api.common.query.ShopGoodsQtyQuery;
import com.ibeeking.found.cms.api.feign.CmsGoodsFeignCClient;
import com.ibeeking.found.cms.api.feign.CmsMarketingFeignCClient;
import com.ibeeking.found.cms.api.feign.CmsSystemCClient;
import com.ibeeking.found.cms.c.rest.service.IPageBaseService;
import com.ibeeking.found.cms.c.rest.service.IPageModuleService;
import com.ibeeking.found.cms.service.common.bo.PageBaseBO;
import com.ibeeking.found.cms.service.common.bo.PageModuleBO;
import com.ibeeking.found.cms.service.common.constants.Constant;
import com.ibeeking.found.cms.service.common.constants.RedisKey;
import com.ibeeking.found.cms.service.common.constants.enums.PageCategoryEnum;
import com.ibeeking.found.cms.service.common.constants.enums.PageModuleDataEnum;
import com.ibeeking.found.cms.service.common.constants.enums.PageModuleTypeEnum;
import com.ibeeking.found.cms.service.common.dos.PageModuleDO;
import com.ibeeking.found.cms.service.common.param.ArticleSourceParam;
import com.ibeeking.found.cms.service.common.param.CampaignSeckillAutoConfigParam;
import com.ibeeking.found.cms.service.common.param.CampaignSeckillManualParam;
import com.ibeeking.found.cms.service.common.param.CampaignSeckillRoundParam;
import com.ibeeking.found.cms.service.common.param.CouponAutoParam;
import com.ibeeking.found.cms.service.common.param.CouponParam;
import com.ibeeking.found.cms.service.common.param.GoodGroupParam;
import com.ibeeking.found.cms.service.common.param.ImageListParam;
import com.ibeeking.found.cms.service.common.query.PageModuleChildDataPageListQuery;
import com.ibeeking.found.cms.service.common.query.PageModuleChildDataQuery;
import com.ibeeking.found.cms.service.common.query.PageModuleDataQuery;
import com.ibeeking.found.cms.service.common.query.PageModuleDataSelQuery;
import com.ibeeking.found.cms.service.common.vo.FrequencyVO;
import com.ibeeking.found.cms.service.common.vo.PageModuleAllView;
import com.ibeeking.found.cms.service.common.vo.PageModuleChildDataGoodsGroupVO;
import com.ibeeking.found.cms.service.common.vo.PageModuleDataBaseVO;
import com.ibeeking.found.cms.service.common.vo.PageModuleDataCommonArticleVO;
import com.ibeeking.found.cms.service.common.vo.PageModuleDataCommonGoodsVO;
import com.ibeeking.found.cms.service.common.vo.PageModuleDataCommonImageAdVO;
import com.ibeeking.found.cms.service.common.vo.PageModuleDataCommonPointsExchangeVO;
import com.ibeeking.found.cms.service.common.vo.PageModuleDataCommonSeckillRoundVO;
import com.ibeeking.found.cms.service.common.vo.PageModuleDataCommonSeckillVO;
import com.ibeeking.found.cms.service.common.vo.PageModuleDataCouponVO;
import com.ibeeking.found.cms.service.common.vo.PageModuleDataGoodsGroupVO;
import com.ibeeking.found.cms.service.common.vo.PageModuleDataShopVO;
import com.ibeeking.found.cms.service.common.vo.PageModuleView;
import com.ibeeking.found.cms.service.mapper.PageModuleMapper;
import com.ibeeking.found.common.enums.PageTypeEnum;
import com.ibeeking.found.common.enums.PublishStatusEnum;
import com.ibeeking.found.common.enums.goods.GoodsChannelEnum;
import com.ibeeking.found.common.enums.goods.GoodsStatusEnum;
import com.ibeeking.found.common.enums.marketing.CampaignSceneEnum;
import com.ibeeking.found.common.enums.marketing.CampaignStatusEnum;
import com.ibeeking.found.common.enums.marketing.CheckStatusEnum;
import com.ibeeking.found.common.enums.marketing.CouponStatusEnum;
import com.ibeeking.found.common.utils.DataUtils;
import com.ibeeking.found.common.utils.DateUtils;
import com.ibeeking.found.common.utils.NumberUtils;
import com.ibeeking.found.common.utils.UserUtils;
import com.ibeeking.nematos.core.utils.SpringBeanUtil;
import com.ibeeking.nematos.exception.BusinessException;
import com.ibeeking.nematos.log.utils.LogUtils;
import com.ibeeking.nematos.redis.annotation.CacheQuery;
import com.ibeeking.nematos.redis.utils.RedisUtils;
import com.ibeeking.nematos.utils.bean.BeanUtil;
import com.ibeeking.nematos.utils.data.Collections3;
import com.ibeeking.nematos.utils.data.ParamCheckUtils;
import com.ibeeking.nematos.utils.data.StringUtils;
import com.ibeeking.nematos.utils.json.JsonUtils;
import com.ibeeking.nematos.utils.result.ResponseCodeEnum;
import com.ibeeking.nematos.utils.result.ResponseResult;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Collectors;

import static java.math.BigDecimal.ROUND_UNNECESSARY;

/**
 * @ClassName PageModuleServiceImpl
 * @Description
 * @Author ibeeking
 * @Date 2021-05-08 16:03
 **/
@Service
public class PageModuleServiceImpl extends ServiceImpl<PageModuleMapper, PageModuleDO> implements IPageModuleService {

    @Resource
    private PageModuleMapper pageModuleMapper;
    @Resource
    private IPageBaseService pageBaseServiceImpl;
    @Resource
    private CmsGoodsFeignCClient cmsGoodsFeignCClient;
    @Resource
    private CmsMarketingFeignCClient cmsMarketingFeignCClient;
    @Resource
    private RedisUtils redisUtils;
    @Resource
    private CmsSystemCClient cmsSystemCClient;

    @Override
    public PageModuleAllView viewByPageId(Long pageId) {
        PageBaseBO pageBaseBO = pageBaseServiceImpl.selById(pageId);
        return getBean().baseView(pageBaseBO);
    }

    @Override
    public PageModuleAllView viewByPageCategory(PageCategoryEnum pageCategoryEnum) {
        DataUtils.trueThrowException(pageCategoryEnum == null, "无法获取页面(页面类型不存在)");
        DataUtils.trueThrowException(!pageCategoryEnum.getHasOnlyOne(), "无法获取页面(页面重复)");
        PageBaseBO pageBaseBO = pageBaseServiceImpl.selOneByPageCategory(pageCategoryEnum, UserUtils.getTenantId());
        DataUtils.trueThrowException(pageBaseBO == null, "无法获取页面");
        return getBean().baseView(pageBaseBO);
    }

    @Override
    public PageModuleAllView baseView(PageBaseBO pageBaseBO) {
        if (pageBaseBO == null) {
            throw BusinessException.create("当前页面数据不存在!");
        }
        Long pageId = pageBaseBO.getId();
        List<PageModuleBO> pageModuleBOS = getBean().selByPageId(pageId);
        PageModuleAllView pageModuleAllView = BeanUtil.convertBean(pageBaseBO, PageModuleAllView.class);
        List<PageModuleView> moduleList = new ArrayList<>();
        for (PageModuleBO x : pageModuleBOS) {
            if (PageModuleTypeEnum.CONFIG.getValue().equalsIgnoreCase(x.getType())) {
                //c端去掉CONFIG组件(页面标题组件)
                //获取页面标题
                JSONObject jsonObject = JsonUtils.fromJson(x.getDataField(), JSONObject.class);
                pageModuleAllView.setTitle(Optional.ofNullable(jsonObject).map(obj -> obj.get(Constant.FIELD_TITLE)).map(obj -> obj.toString()).orElse(StringUtils.EMPTY));
                if (pageModuleBOS.size() > 1) {
                    //当组件只有 CONFIG 时不过滤,否则过滤掉
                    continue;
                }
            }
            PageModuleView pageModuleView = new PageModuleView();
            pageModuleView.setId(x.getId());
            pageModuleView.setPageId(x.getPageId());
            pageModuleView.setSort(x.getSort());
            pageModuleView.setType(x.getType());
            pageModuleView.setDataField(JsonUtils.fromJson(x.getDataField(), JSONObject.class));
            moduleList.add(pageModuleView);
        }
        pageModuleAllView.setModuleList(moduleList);
        //记录页面浏览量
        try {
            //总浏览量
            redisUtils.hIncrement(RedisKey.PAGE_BROWSE_COUNT + pageId, RedisKey.PAGE_BROWSE_COUNT_TOTAL_FIELD, 1L);
            //每天的浏览量
            redisUtils.hIncrement(RedisKey.PAGE_BROWSE_COUNT + pageId, DateUtils.getToday(), 1L);
        } catch (Exception e) {
            LogUtils.error("记录页面浏览量异常!", e);
        }
        return pageModuleAllView;
    }

    @CacheQuery(cacheName = RedisKey.PAGE_MODULE_LIST, key = "#pageId")
    @Override
    public List<PageModuleBO> selByPageId(Long pageId) {
        if (pageId == null) {
            return Collections3.emptyList();
        }
        return JsonUtils.jsonToList(pageModuleMapper.selectList(new LambdaQueryWrapper<PageModuleDO>().eq(PageModuleDO::getPageId, pageId).orderByAsc(PageModuleDO::getSort)), PageModuleBO.class);
    }

    @CacheQuery(cacheName = RedisKey.PAGE_MODULE, key = "#id")
    @Override
    public PageModuleBO selById(Long id) {
        if (id == null) {
            return null;
        }
        return BeanUtil.convertBeanByJson(pageModuleMapper.selectById(id), PageModuleBO.class);
    }

    @Override
    public PageModuleView pageModuleData(Long id) {
        PageModuleBO pageModuleBO = getBean().selById(id);
        if (pageModuleBO == null) {
            return null;
        }
        PageModuleView pageModuleView = new PageModuleView();
        pageModuleView.setId(pageModuleBO.getId());
        pageModuleView.setPageId(pageModuleBO.getPageId());
        pageModuleView.setSort(pageModuleBO.getSort());
        pageModuleView.setType(pageModuleBO.getType());
        pageModuleView.setDataField(JsonUtils.fromJson(pageModuleBO.getDataField(), JSONObject.class));
        String type = pageModuleView.getType();
        JSONObject dataField = pageModuleView.getDataField();
        return getBean().pageModuleDataBase(pageModuleView, type, dataField);
    }

    @Override
    public PageModuleView pageModuleData(PageModuleDataQuery query) {
        PageModuleBO pageModuleBO = getBean().selById(query.getId());
        if (pageModuleBO == null) {
            return null;
        }
        PageModuleView pageModuleView = new PageModuleView();
        pageModuleView.setId(pageModuleBO.getId());
        pageModuleView.setPageId(pageModuleBO.getPageId());
        pageModuleView.setSort(pageModuleBO.getSort());
        pageModuleView.setType(pageModuleBO.getType());
        pageModuleView.setDataField(JsonUtils.fromJson(pageModuleBO.getDataField(), JSONObject.class));
        String type = pageModuleView.getType();
        JSONObject dataField = pageModuleView.getDataField();
        return getBean().pageModuleDataBase(pageModuleView, type, dataField);
    }

    @Override
    public PageModuleView pageModuleDataSelQuery(PageModuleDataSelQuery query) {
        return getBean().pageModuleDataBase(new PageModuleView(), query.getType(), query.getDataField());
    }

    @Override
    public PageModuleView pageModuleDataBase(PageModuleView pageModuleView, String type, JSONObject dataField) {
        List<String> msgs = Collections3.newArrayList();
        DataUtils.trueThrowException(StringUtils.isBlank(type), "获取页面组件数据异常(组件类型为空)!");
        pageModuleView = pageModuleView == null ? new PageModuleView() : pageModuleView;
        if (pageModuleView.getDataField() == null) {
            pageModuleView.setDataField(dataField);
        }
        if (StringUtils.isBlank(pageModuleView.getType())) {
            pageModuleView.setType(type);
        }
        if (dataField == null) {
            return pageModuleView;
        }
        Object id = dataField.get(Constant.FIELD_ID);
        if (pageModuleView.getId() == null) {
            pageModuleView.setId(id == null ? null : Long.valueOf(id.toString()));
        }
        List pageModuleDataCommonVOS = CollUtil.newArrayList();
        if (PageModuleTypeEnum.GOODS.getValue().equalsIgnoreCase(type)) {
            //商品数据
            Object obj = dataField.get(PageModuleDataEnum.GOODS.getValue());
            List<Long> goodsIds = JsonUtils.jsonToList(obj, Long.class);
            if (Collections3.isEmpty(goodsIds)) {
                return pageModuleView;
            }
            ResponseResult<List<GoodsDTO>> responseResult = cmsGoodsFeignCClient.listByGoods(goodsIds);
            List<GoodsDTO> goodsDTOS = Optional.ofNullable(responseResult).map(ResponseResult::getData).orElse(Collections3.emptyList());
            msgs.add(DataUtils.methodMsg("cmsGoodsFeignCClient.listByGoods", goodsIds, responseResult));

            Map<Long, GoodsDTO> goodsDTOMap = goodsDTOS.stream().collect(Collectors.toMap(GoodsDTO::getId, x -> x, (o, n) -> n));
            goodsIds.forEach(goodsId -> {
                GoodsDTO goodsDTO = goodsDTOMap.get(goodsId);
                if (goodsDTO == null) {
                    return;
                }
                PageModuleDataCommonGoodsVO pageModuleDataCommonVO = new PageModuleDataCommonGoodsVO();
                pageModuleDataCommonVO.setId(goodsId);
                pageModuleDataCommonVO.setGoodsId(goodsId);
                pageModuleDataCommonVO.setName(goodsDTO.getName());
                pageModuleDataCommonVO.setImgUrl(goodsDTO.getThumb());
                pageModuleDataCommonVO.setPrice(NumberUtils.cent2Yuan(goodsDTO.getPrice()));
                pageModuleDataCommonVO.setStock(goodsDTO.getStock());
                pageModuleDataCommonVO.setSaleStock(goodsDTO.getSaleStock());
                pageModuleDataCommonVO.setMarkingPrice(NumberUtils.cent2Yuan(goodsDTO.getMarkingPrice()));
                pageModuleDataCommonVO.setChannel(GoodsChannelEnum.GOODS.getValue());
                pageModuleDataCommonVO.setGoodsTagsNames(goodsDTO.getGoodsTagsNames());
                pageModuleDataCommonVOS.add(pageModuleDataCommonVO);
            });
        } else if (PageModuleTypeEnum.GOODS_CATEGORY_ROOT.getValue().equalsIgnoreCase(type)) {
            //商品类目数据
            ResponseResult<List<GoodsCategoryDTO>> responseResult = cmsGoodsFeignCClient.goodsCategoryEffectiveRootDtoList();
            List<GoodsCategoryDTO> goodsCategoryDTOS = Optional.ofNullable(responseResult).map(ResponseResult::getData).orElse(Collections3.emptyList());
            msgs.add(DataUtils.methodMsg("cmsGoodsFeignCClient.goodsCategoryEffectiveRootDtoList", null, responseResult));
            if (Collections3.isEmpty(goodsCategoryDTOS)) {
                return pageModuleView;
            }
            goodsCategoryDTOS.forEach(dto -> {
                PageModuleDataBaseVO pageModuleDataCommonVO = new PageModuleDataBaseVO();
                pageModuleDataCommonVO.setId(dto.getId());
                pageModuleDataCommonVO.setName(dto.getName());
                pageModuleDataCommonVO.setImgUrl(dto.getPic());
                pageModuleDataCommonVOS.add(pageModuleDataCommonVO);
            });
        } else if (PageModuleTypeEnum.ACTIVITY_LIST.getValue().equalsIgnoreCase(type)) {

        } else if (PageModuleTypeEnum.POINTS_EXCHANGE.getValue().equalsIgnoreCase(type)) {
            //获取活动
            Object obj = dataField.get(PageModuleDataEnum.ID_OBJ_S.getValue());
            List<CampaignLowPriceFeignQuery> paramList = JsonUtils.jsonToList(obj, CampaignLowPriceFeignQuery.class);
            if (Collections3.isEmpty(paramList)) {
                return pageModuleView;
            }
            //查询活动
            ResponseResult<List<CampaignLowPriceDTO>> listResponseResult = cmsMarketingFeignCClient.queryGoodsLowPrice(paramList);
            msgs.add(DataUtils.methodMsg("cmsMarketingFeignCClient.queryGoodsLowPrice", paramList, listResponseResult));
            List<CampaignLowPriceDTO> campaignListDTOS = Optional.ofNullable(listResponseResult.getData()).orElse(Collections3.emptyList());
            Map<Long, CampaignLowPriceDTO> dtoMap = campaignListDTOS.stream().collect(Collectors.toMap(CampaignLowPriceDTO::getId, x -> x, (o, n) -> n));

            //查询商品
            List<Long> goodsIds = campaignListDTOS.stream().map(CampaignLowPriceDTO::getUnionId).collect(Collectors.toList());
            ResponseResult<List<GoodsDTO>> responseResult = cmsGoodsFeignCClient.listByGoods(goodsIds);
            List<GoodsDTO> goodsDTOS = Optional.ofNullable(responseResult).map(ResponseResult::getData).orElse(Collections3.emptyList());
            msgs.add(DataUtils.methodMsg("cmsGoodsFeignCClient.listByGoods", goodsIds, responseResult));
            Map<Long, GoodsDTO> goodsDTOMap = goodsDTOS.stream().collect(Collectors.toMap(GoodsDTO::getId, x -> x, (o, n) -> n));

            paramList.forEach(x -> {
                CampaignLowPriceDTO campaignLowPriceDTO = dtoMap.get(x.getCampaignId());
                GoodsDTO goodsDTO = goodsDTOMap.get(x.getGoodsId());
                if (campaignLowPriceDTO == null || goodsDTO == null) {
                    return;
                }
                PageModuleDataCommonPointsExchangeVO pageModuleDataCommonVO = new PageModuleDataCommonPointsExchangeVO();
                pageModuleDataCommonVO.setChannel(x.getChannel());
                pageModuleDataCommonVO.setId(campaignLowPriceDTO.getId());
                pageModuleDataCommonVO.setImgUrl(goodsDTO.getThumb());
                pageModuleDataCommonVO.setName(goodsDTO.getName());
                pageModuleDataCommonVO.setGoodsId(campaignLowPriceDTO.getUnionId());
                pageModuleDataCommonVO.setSkuId(campaignLowPriceDTO.getGoodsSkuId());
                pageModuleDataCommonVO.setPrice(NumberUtils.cent2Yuan(campaignLowPriceDTO.getPrice()));
                pageModuleDataCommonVO.setMarkingPrice(NumberUtils.cent2Yuan(goodsDTO.getMarkingPrice()));
                pageModuleDataCommonVO.setPoints(campaignLowPriceDTO.getPoints());
                pageModuleDataCommonVO.setStock(goodsDTO.getStock());
                pageModuleDataCommonVO.setSaleStock(goodsDTO.getSaleStock());

                pageModuleDataCommonVO.setActivityId(campaignLowPriceDTO.getId());
                pageModuleDataCommonVO.setActivityName(campaignLowPriceDTO.getName());
                pageModuleDataCommonVO.setStatus(campaignLowPriceDTO.getCampaignStatus());
                pageModuleDataCommonVO.setStatusDesc(campaignLowPriceDTO.getCampaignStatusName());
                pageModuleDataCommonVO.setActivityType(campaignLowPriceDTO.getSceneCode());
                pageModuleDataCommonVO.setActivityTypeName(campaignLowPriceDTO.getSceneName());
                pageModuleDataCommonVO.setActivityValidityStart(campaignLowPriceDTO.getStartTime());
                pageModuleDataCommonVO.setActivityValidityEnd(campaignLowPriceDTO.getEndTime());
                pageModuleDataCommonVO.setActivityLeftTime(campaignLowPriceDTO.getDistanceTimeMillis());
                if (pageModuleDataCommonVO.getChannel() == null) {
                    pageModuleDataCommonVO.setChannel(campaignLowPriceDTO.getChannel());
                }
                pageModuleDataCommonVOS.add(pageModuleDataCommonVO);
            });
        } else if (PageModuleTypeEnum.IMAGE_AD.getValue().equalsIgnoreCase(type)) {
            Object obj = dataField.get(PageModuleDataEnum.IMAGE_AD.getValue());
            List<ImageListParam> paramList = JsonUtils.jsonToList(obj, ImageListParam.class);
            if (Collections3.isEmpty(paramList)) {
                return pageModuleView;
            }
            LocalDateTime now = LocalDateTime.now();
            paramList = paramList.stream().filter(x -> {
                List<String> showTimeList = x.getShowTime();
                if (Collections3.isEmpty(showTimeList) || Collections3.size(showTimeList) != 2) {
                    return true;
                }
                Boolean showStart;
                Boolean showEnd;
                String showStartTime = showTimeList.get(0);
                String showEndTime = showTimeList.get(1);
                try {
                    if (org.apache.commons.lang.StringUtils.isNotBlank(showStartTime)) {
                        showStart = DateUtils.strToLocalDateTime(showStartTime).compareTo(now) <= 0;
                    } else {
                        showStart = true;
                    }
                    if (org.apache.commons.lang.StringUtils.isNotBlank(showEndTime)) {
                        showEnd = DateUtils.strToLocalDateTime(showEndTime).compareTo(now) >= 0;
                    } else {
                        showEnd = true;
                    }
                } catch (Exception e) {
                    LogUtils.error("图片广告组件,时间比较异常!", e);
                    return false;
                }
                return showStart && showEnd;
            }).collect(Collectors.toList());

            //推广活动 要展示报名状态
            Map<Long, CampaignInfoDTO> promotionCampaignMap = new HashMap<>();
            List<Long> promotionCampaignIds = paramList.stream().filter(x -> CampaignSceneEnum.PROMOTION_SCENE.getChannel().equals(x.getChannel())).map(ImageListParam::getActivityId).collect(Collectors.toList());
            if (Collections3.isNotEmpty(promotionCampaignIds)) {
                ResponseResult<List<CampaignInfoDTO>> promotionCampaignResult = cmsMarketingFeignCClient.queryCampaignInfoDTO(new FeignCampaignQuery().setCampaignIds(promotionCampaignIds).setCheckStatus(CheckStatusEnum.CHECKED.getCode()).setCampaignStatusList(Collections3.newArrayList(CampaignStatusEnum.NOT_STARTED.getCode(), CampaignStatusEnum.IN_PROGRESS.getCode(), CampaignStatusEnum.EXPIRED.getCode())));
                List<CampaignInfoDTO> promotionCampaigns = promotionCampaignResult.getData();
                if (Collections3.isNotEmpty(promotionCampaigns)) {
                    promotionCampaignMap = promotionCampaigns.stream().collect(Collectors.toMap(CampaignInfoDTO::getId, x -> x));
                }
            }
            Map<Long, CampaignInfoDTO> promotionCampaignMapFinal = promotionCampaignMap;
            List<PageModuleDataCommonImageAdVO> voList = JsonUtils.jsonToList(paramList, PageModuleDataCommonImageAdVO.class);
            voList.forEach(pageModuleDataCommonVO -> {
                pageModuleDataCommonVO.setId(pageModuleDataCommonVO.getId());
                pageModuleDataCommonVO.setImgUrl(pageModuleDataCommonVO.getUrl());
                pageModuleDataCommonVO.setName(pageModuleDataCommonVO.getTitle());
                pageModuleDataCommonVO.setType(pageModuleDataCommonVO.getType());
                pageModuleDataCommonVO.setLink(pageModuleDataCommonVO.getLink());
                pageModuleDataCommonVO.setChannel(pageModuleDataCommonVO.getChannel());
                if (PageTypeEnum.GOODS.getValue().equals(pageModuleDataCommonVO.getType())) {
                    pageModuleDataCommonVO.setGoodsId(Long.valueOf(pageModuleDataCommonVO.getLink()));
                    pageModuleDataCommonVO.setId(pageModuleDataCommonVO.getGoodsId());
                    pageModuleDataCommonVO.setChannel(GoodsChannelEnum.GOODS.getValue());
                } else if (PageTypeEnum.ACTIVITY.getValue().equals(pageModuleDataCommonVO.getType())) {
                    pageModuleDataCommonVO.setActivityId(pageModuleDataCommonVO.getActivityId());
                    pageModuleDataCommonVO.setGoodsId(pageModuleDataCommonVO.getGoodsId());
                    pageModuleDataCommonVO.setChannel(pageModuleDataCommonVO.getChannel());
                    if (promotionCampaignMapFinal.get(pageModuleDataCommonVO.getActivityId()) != null) {
                        pageModuleDataCommonVO.setIsTag(true);
                        pageModuleDataCommonVO.setLabelName(promotionCampaignMapFinal.get(pageModuleDataCommonVO.getActivityId()).getEnrollStatusName());
                    }
                }
                pageModuleDataCommonVOS.add(pageModuleDataCommonVO);
            });
        } else if (PageModuleTypeEnum.MARKETING_COUPON.getValue().equalsIgnoreCase(type)) {
            //优惠券添加方式 0手动 1自动
            Integer addType = Integer.valueOf(Objects.toString(dataField.get("addType")));
            //失效或抢完券 是否展示
            Integer invalid = Integer.valueOf(Objects.toString(dataField.get("invalid")));
            if (addType == 0) {
                //0手动 获取选中的券列表
                List<CouponParam> couponList = JsonUtils.jsonToList(dataField.get(PageModuleDataEnum.MARKETING_COUPON_MANUAL.getValue()), CouponParam.class);
                if (Collections3.isNotEmpty(couponList)) {
                    List<Long> couponIdList = couponList.stream().map(CouponParam::getId).collect(Collectors.toList());
                    ResponseResult<List<CouponInfoDTO>> listResponseResult = cmsMarketingFeignCClient.queryInfoByIds(couponIdList);
                    DataUtils.falseThrowException(ResponseCodeEnum.SUCCESS.getCode().equals(listResponseResult.getCode()), "系统异常,未查询到券信息!");
                    List<CouponInfoDTO> couponInfoList = listResponseResult.getData();
                    if (Collections3.isNotEmpty(couponInfoList)) {
                        Map<Long, CouponInfoDTO> couponInfoDTOMap = couponInfoList.stream().collect(Collectors.toMap(CouponInfoDTO::getId, x -> x, (o, n) -> n));
                        PageModuleDataCouponVO pageModuleDataCouponVO;
                        for (Long couponId : couponIdList) {
                            CouponInfoDTO couponInfoDTO = couponInfoDTOMap.get(couponId);
                            if (couponInfoDTO != null) {
                                //失效或抢完券 是否展示
                                if (invalid == 0) {
                                    //失效或抢完券隐藏
                                    if (CouponStatusEnum.TERMINATE.getCode().equals(couponInfoDTO.getCouponStatus()) || CouponStatusEnum.EXPIRED.getCode().equals(couponInfoDTO.getCouponStatus())) {
                                        //已过期/已终止排除
                                        continue;
                                    }
                                    //todo 抢完券的情况
                                }
                                pageModuleDataCouponVO = JsonUtils.fromJson(couponInfoDTO, PageModuleDataCouponVO.class);
                                pageModuleDataCouponVO.setNumber(com.ibeeking.nematos.utils.data.DataUtils.fromFenToYuan(couponInfoDTO.getWorth(), 2, ROUND_UNNECESSARY));
                                pageModuleDataCouponVO.setDesc(couponInfoDTO.getNameRemark());
                                pageModuleDataCommonVOS.add(pageModuleDataCouponVO);
                            }
                        }
                    }
                }
            } else {
                // 1自动获取券
                CouponAutoParam couponAutoParam = JsonUtils.fromJson(dataField.get(PageModuleDataEnum.MARKETING_COUPON_AUTO.getValue()), CouponAutoParam.class);
                if (couponAutoParam != null) {
                    CouponInfoPageQuery couponInfoPageQuery = JsonUtils.fromJson(couponAutoParam, CouponInfoPageQuery.class);
                    couponInfoPageQuery.setPageNum(1);
                    couponInfoPageQuery.setPageSize(couponAutoParam.getShowMaxQty());
                    couponInfoPageQuery.setEffective(true);
                    //失效或抢完券 是否展示
                    if (invalid == 0) {
                        //todo 抢完券的情况
                    }
                    ResponseResult<com.ibeeking.nematos.utils.base.Page<CouponInfoPageDTO>> listResponseResult = cmsMarketingFeignCClient.couponPageList(couponInfoPageQuery);
                    DataUtils.falseThrowException(ResponseCodeEnum.SUCCESS.getCode().equals(listResponseResult.getCode()), "系统异常,未查询到券信息!");
                    List<CouponInfoPageDTO> couponInfoList = Optional.ofNullable(listResponseResult.getData()).map(x -> x.getRecords()).orElse(null);
                    if (Collections3.isNotEmpty(couponInfoList)) {
                        PageModuleDataCouponVO pageModuleDataCouponVO;
                        for (CouponInfoPageDTO couponInfoDTO : couponInfoList) {
                            pageModuleDataCouponVO = JsonUtils.fromJson(couponInfoDTO, PageModuleDataCouponVO.class);
                            pageModuleDataCouponVO.setNumber(couponInfoDTO.getWorthNum());
                            pageModuleDataCouponVO.setDesc(couponInfoDTO.getNameRemark());
                            pageModuleDataCommonVOS.add(pageModuleDataCouponVO);
                        }
                    }
                }
            }
        } else if (PageModuleTypeEnum.GOODS_GROUP.getValue().equalsIgnoreCase(type)) {
            Object obj = dataField.get(PageModuleDataEnum.GOODS_GROUP.getValue());
            List<GoodGroupParam> paramList = JsonUtils.jsonToList(obj, GoodGroupParam.class);
            if (Collections3.isEmpty(paramList)) {
                return pageModuleView;
            }
            List<Long> groupIds = paramList.stream().map(GoodGroupParam::getId).collect(Collectors.toList());
            ResponseResult<List<GoodsGroupBaseDTO>> listResponseResult = cmsGoodsFeignCClient.queryGoodsGroupByIds(groupIds);
            DataUtils.falseThrowException(ResponseCodeEnum.SUCCESS.getCode().equals(listResponseResult.getCode()), "系统异常,未查询到商品分组!");
            List<GoodsGroupBaseDTO> goodsGroupList = listResponseResult.getData();
            Map<Long, GoodsGroupBaseDTO> map = goodsGroupList.stream().collect(Collectors.toMap(GoodsGroupBaseDTO::getId, x -> x, (o, n) -> n));
            paramList.forEach(x -> {
                GoodsGroupBaseDTO goodsGroupBaseDTO = map.get(x.getId());
                if (goodsGroupBaseDTO != null && PublishStatusEnum.ENABLE.getValue().equals(goodsGroupBaseDTO.getPublishStatus()) && goodsGroupBaseDTO.getStatus() == 1) {
                    PageModuleDataGoodsGroupVO pageModuleDataGoodsGroupVO = JsonUtils.fromJson(x, PageModuleDataGoodsGroupVO.class);
                    pageModuleDataGoodsGroupVO.setId(x.getId());
                    pageModuleDataGoodsGroupVO.setName(x.getGroupName());
                    pageModuleDataGoodsGroupVO.setSource(goodsGroupBaseDTO.getName());
                    pageModuleDataCommonVOS.add(pageModuleDataGoodsGroupVO);
                }
            });
        } else if (PageModuleTypeEnum.SHOP.getValue().equalsIgnoreCase(type)) {
            Object obj = dataField.get("shopId");
            DataUtils.trueThrowException(obj == null, "无法获取店铺信息!");
            Long shopId = Long.valueOf(obj.toString());
            ResponseResult<CmsShopModuleInfoDTO> cmsShopModuleInfoDTOResponseResult = cmsSystemCClient.cmsShopModuleInfo(shopId);
            CmsShopModuleInfoDTO data = cmsShopModuleInfoDTOResponseResult.getData();
            DataUtils.trueThrowException(data == null, "获取店铺信息失败!");
            ResponseResult<Integer> shopGoodsQtyRes = cmsGoodsFeignCClient.queryShopGoodsQty(new ShopGoodsQtyQuery().setShopId(shopId).setGoodsChannel(GoodsChannelEnum.GOODS.getValue()).setGoodsStatus(GoodsStatusEnum.ON_SHELF.getValue()));
            PageModuleDataShopVO pageModuleDataShopVO = BeanUtil.convertBean(data, PageModuleDataShopVO.class);
            pageModuleDataShopVO.setOldShopName(data.getName());
            String name = Objects.toString(dataField.get("name"));
            pageModuleDataShopVO.setName(StringUtils.isBlank(name) ? data.getName() : name);
            pageModuleDataShopVO.setGoodsTotalQty(shopGoodsQtyRes.getData());
            pageModuleDataShopVO.setImgUrl(pageModuleDataShopVO.getLogo());
            pageModuleDataCommonVOS.add(pageModuleDataShopVO);
        } else if (PageModuleTypeEnum.SECKILL.getValue().equalsIgnoreCase(type)) {
            //活动添加方式 0手动 1自动
            List<CampaignSeckillRoundParam> campaignSeckillRoundList = JsonUtils.jsonToList(dataField.get(PageModuleDataEnum.MARKETING_SECKILL_ROUND_LIST.getValue()), CampaignSeckillRoundParam.class);
            String today = DateUtil.today();
            if (Collections3.isNotEmpty(campaignSeckillRoundList)) {
                List<PageModuleDataCommonSeckillRoundVO> pageModuleDataCommonSeckillRoundVOS = JsonUtils.jsonToList(campaignSeckillRoundList, PageModuleDataCommonSeckillRoundVO.class);
                for (PageModuleDataCommonSeckillRoundVO seckillRoundVO : pageModuleDataCommonSeckillRoundVOS) {
                    String startTime = seckillRoundVO.getStartTime();
                    String endTime = seckillRoundVO.getEndTime();
                    DateTime now = DateUtil.date();
                    boolean in = DateUtil.isIn(now, DateUtil.parse(DateUtils.dayStartStr(startTime)).toJdkDate(), DateUtil.parse(DateUtils.dayEndStr(endTime)).toJdkDate());
                    if (!in) {
                        //场次不在时间范围内
                        continue;
                    }
                    List<FrequencyVO> frequencyList = seckillRoundVO.getFrequencyList();
                    List<Integer> frequencyCodeList = frequencyList.stream().filter(x -> x.getEnable()).map(FrequencyVO::getCode).collect(Collectors.toList());
                    int dayOfWeek = DateUtil.dayOfWeek(now) - 1;
                    dayOfWeek = dayOfWeek == 0 ? 7 : dayOfWeek;
                    if (!frequencyCodeList.contains(dayOfWeek)) {
                        //场次星期几不在范围内
                        continue;
                    }
                    String seckillRoundTodayStartTime = today + seckillRoundVO.getStartTimePeriod();
                    String seckillRoundTodayEndTime = today + seckillRoundVO.getEndTimePeriod();

                    //针对秒杀处理时间
                    if (LocalDateTime.now().toString().compareTo(seckillRoundTodayStartTime) < 0) {
                        seckillRoundVO.setStatus(CampaignStatusEnum.NOT_STARTED.getCode());
                        seckillRoundVO.setStatusDesc(CampaignStatusEnum.NOT_STARTED.getLable());
                        //活动未开始 计算距离活动开始时间的毫秒值
                        seckillRoundVO.setLeftTime(DateUtil.betweenMs(Calendar.getInstance().getTime(), DateUtils.parseDate(seckillRoundTodayStartTime)));
                    } else if (LocalDateTime.now().toString().compareTo(seckillRoundTodayStartTime) >= 0 && LocalDateTime.now().toString().compareTo(seckillRoundTodayEndTime) <= 0) {
                        seckillRoundVO.setStatus(CampaignStatusEnum.IN_PROGRESS.getCode());
                        seckillRoundVO.setStatusDesc(CampaignStatusEnum.IN_PROGRESS.getLable());
                        //活动进行中 计算距离活动结束时间的毫秒值
                        seckillRoundVO.setLeftTime(DateUtil.betweenMs(Calendar.getInstance().getTime(), DateUtils.parseDate(seckillRoundTodayEndTime)));
                    } else if (LocalDateTime.now().toString().compareTo(seckillRoundTodayEndTime) > 0) {
                        seckillRoundVO.setStatus(CampaignStatusEnum.EXPIRED.getCode());
                        seckillRoundVO.setStatusDesc(CampaignStatusEnum.EXPIRED.getLable());
                    }
                    pageModuleDataCommonVOS.add(seckillRoundVO);
                }
            }
        } else if (PageModuleTypeEnum.ARTICLE.getValue().equalsIgnoreCase(type)) {
            ArticleSourceParam articleSourceParam = JsonUtils.fromJson(dataField.get(PageModuleDataEnum.ARTICLE_SOURCE.getValue()), ArticleSourceParam.class);
            if (articleSourceParam != null) {
                int articleSource = articleSourceParam.getArticleSource();
                if (ArticleSourceParam.ARTICLE_SOURCE_ARTICLE_LIST == articleSource) {
                    ArticleQuery articleQuery = new ArticleQuery();
                    //文章来源方式-文章列表
                    articleQuery.setIds(articleSourceParam.getArticleIdList());
                    articleQuery.setPublishStatus(PublishStatusEnum.ENABLE.getValue());
                    ResponseResult<List<ArticleDTO>> articleListResult = cmsMarketingFeignCClient.articleList(articleQuery);
                    DataUtils.falseThrowException(ResponseCodeEnum.SUCCESS.getCode().equals(articleListResult.getCode()), "未查询到文章信息");
                    List<PageModuleDataCommonArticleVO> pageModuleDataCommonArticleVOS = JsonUtils.jsonToList(articleListResult.getData(), PageModuleDataCommonArticleVO.class);
                    for (PageModuleDataCommonArticleVO vo : pageModuleDataCommonArticleVOS) {
                        vo.setName(vo.getTitle());
                        if (Collections3.isNotEmpty(vo.getCoverImgList())) {
                            vo.setImgUrl(vo.getCoverImgList().get(0));
                        }
                    }
                    pageModuleDataCommonVOS.addAll(pageModuleDataCommonArticleVOS);
                } else {
                    ArticleGroupQuery articleGroupQuery = new ArticleGroupQuery().setIds(articleSourceParam.getGroupIdList());
                    ResponseResult<List<ArticleGroupDTO>> articleGroupListResult = cmsMarketingFeignCClient.articleGroupList(articleGroupQuery);
                    DataUtils.falseThrowException(ResponseCodeEnum.SUCCESS.getCode().equals(articleGroupListResult.getCode()), "未查询到文章信息");
                    List<PageModuleDataBaseVO> pageModuleDataBaseVOS = JsonUtils.jsonToList(articleGroupListResult.getData(), PageModuleDataBaseVO.class);
                    pageModuleDataCommonVOS.addAll(pageModuleDataBaseVOS);
                }
            }
        }
        pageModuleView.setItems(pageModuleDataCommonVOS);
        pageModuleView.setMsgs(msgs);
        return pageModuleView;
    }

    @Override
    public List pageModuleChildData(PageModuleChildDataQuery query) {
        PageModuleBO pageModuleBO = getBean().selById(query.getId());
        if (pageModuleBO == null) {
            return Collections3.emptyList();
        }
        JSONObject jsonObject = JsonUtils.fromJson(pageModuleBO.getDataField(), JSONObject.class);
        String type = pageModuleBO.getType();
        String childId = query.getChildId();
        return getBean().pageModuleChildDataBase(childId, type, jsonObject);
    }

    @Override
    public List pageModuleChildDataBase(String childId, String type, JSONObject dataField) {
        if (PageModuleTypeEnum.GOODS_GROUP.getValue().equalsIgnoreCase(type)) {
            Object obj = dataField.get(PageModuleDataEnum.GOODS_GROUP.getValue());
            List<GoodGroupParam> paramList = JsonUtils.jsonToList(obj, GoodGroupParam.class);
            if (Collections3.isEmpty(paramList)) {
                return Collections3.emptyList();
            }
            GoodGroupParam goodGroupParam = paramList.stream().filter(x -> childId.equals(Objects.toString(x.getId()))).findFirst().orElse(null);
            if (goodGroupParam == null) {
                return Collections3.emptyList();
            }
            Integer goodsNumType = goodGroupParam.getGoodsNumType();
            GoodsByGroupQuery goodsByGroupQuery = new GoodsByGroupQuery();
            goodsByGroupQuery.setGoodsGroupId(Long.valueOf(childId));
            goodsByGroupQuery.setGoodsNum(goodsNumType == 2 ? null : goodGroupParam.getGoodsNum());
            goodsByGroupQuery.setChannels(Arrays.asList(GoodsChannelEnum.GOODS.getValue()));
            goodsByGroupQuery.setStatus(GoodsStatusEnum.ON_SHELF.getValue());
            ResponseResult<List<GoodsVoDTO>> listResponseResult = cmsGoodsFeignCClient.queryGoodsByGroup(goodsByGroupQuery);
            DataUtils.falseThrowException(ResponseCodeEnum.SUCCESS.getCode().equals(listResponseResult.getCode()), "系统异常,未查询到商品分组下的商品!");
            List<GoodsVoDTO> dataList = listResponseResult.getData();
            List<PageModuleChildDataGoodsGroupVO> pageModuleChildDataGoodsGroupVOS = new ArrayList<>();
            PageModuleChildDataGoodsGroupVO vo;
            for (GoodsVoDTO goodsVoDTO : dataList) {
                vo = JsonUtils.fromJson(goodsVoDTO, PageModuleChildDataGoodsGroupVO.class);
                if (vo != null) {
                    vo.setId(goodsVoDTO.getId());
                    vo.setGoodsId(goodsVoDTO.getId());
                    vo.setSkuId(goodsVoDTO.getDefaultSkuId());
                    vo.setImgUrl(goodsVoDTO.getThumb());
                    vo.setStock(goodsVoDTO.getEffectiveStock());
                    vo.setChannel(GoodsChannelEnum.GOODS.getValue());
                    String goodsTagsNames = goodsVoDTO.getGoodsTagsNames();
                    if (org.apache.commons.lang.StringUtils.isNotBlank(goodsTagsNames)) {
                        String[] goodsTagsNameArr = goodsTagsNames.split(",");
                        vo.setGoodsTagsNameList(CollUtil.newArrayList(goodsTagsNameArr));
                    } else {
                        vo.setGoodsTagsNameList(Collections3.emptyList());
                    }
                    pageModuleChildDataGoodsGroupVOS.add(vo);
                }
            }
            return pageModuleChildDataGoodsGroupVOS;
        } else if (PageModuleTypeEnum.ARTICLE.getValue().equalsIgnoreCase(type)) {
            ArticleSourceParam articleSourceParam = JsonUtils.fromJson(dataField.get(PageModuleDataEnum.ARTICLE_SOURCE.getValue()), ArticleSourceParam.class);
            if (articleSourceParam != null) {
                int articleSource = articleSourceParam.getArticleSource();
                if (ArticleSourceParam.ARTICLE_SOURCE_GROUP_LIST == articleSource) {
                    //文章来源方式-分组列表
                    List<PageModuleDataBaseVO> pageModuleDataBaseVOS = new ArrayList<>();
                    if (CollUtil.isNotEmpty(articleSourceParam.getGroupIdList())) {
                        ArticleGroupQuery articleGroupQuery = new ArticleGroupQuery().setIds(articleSourceParam.getGroupIdList());
                        ResponseResult<List<ArticleGroupDTO>> articleGroupListResult = cmsMarketingFeignCClient.articleGroupList(articleGroupQuery);
                        DataUtils.falseThrowException(ResponseCodeEnum.SUCCESS.getCode().equals(articleGroupListResult.getCode()), "未查询到文章分组信息");
                        pageModuleDataBaseVOS = JsonUtils.jsonToList(articleGroupListResult.getData(), PageModuleDataBaseVO.class);
                    }
                    return pageModuleDataBaseVOS;
                } else if (ArticleSourceParam.ARTICLE_SOURCE_ARTICLE_LIST == articleSource) {
                    ArticleQuery articleQuery = new ArticleQuery();
                    if (CollUtil.isNotEmpty(articleSourceParam.getArticleIdList())) {
                        //文章来源方式-文章列表
                        articleQuery.setIds(articleSourceParam.getArticleIdList());
                        ResponseResult<List<ArticleDTO>> articleListResult = cmsMarketingFeignCClient.articleList(articleQuery);
                        DataUtils.falseThrowException(ResponseCodeEnum.SUCCESS.getCode().equals(articleListResult.getCode()), "未查询到文章信息");
                        List<PageModuleDataCommonArticleVO> pageModuleDataCommonArticleVOS = JsonUtils.jsonToList(articleListResult.getData(), PageModuleDataCommonArticleVO.class);
                        for (PageModuleDataCommonArticleVO vo : pageModuleDataCommonArticleVOS) {
                            vo.setName(vo.getTitle());
                            if (Collections3.isNotEmpty(vo.getCoverImgList())) {
                                vo.setImgUrl(vo.getCoverImgList().get(0));
                            }
                        }
                        return pageModuleDataCommonArticleVOS;
                    }
                }
            }
        }
        return Collections3.emptyList();
    }

    @Override
    public Page pageModuleChildDataPageList(PageModuleChildDataPageListQuery query) {
        Page pageRes = new Page(query.getPageNum(), query.getPageSize());
        String type = query.getType();
        Integer pageNum = query.getPageNum();
        Integer pageSize = query.getPageSize();
        Object childDataParam = query.getChildDataParam();
        if (PageModuleTypeEnum.SECKILL.getValue().equalsIgnoreCase(type)) {
            CampaignSeckillRoundParam campaignSeckillRoundParam = JsonUtils.fromJson(childDataParam, CampaignSeckillRoundParam.class);
            ParamCheckUtils.check(campaignSeckillRoundParam);
            Integer addType = campaignSeckillRoundParam.getAddType();
            CampaignPageListQuery campaignPageListQuery = new CampaignPageListQuery();
            campaignPageListQuery.setPageNum(pageNum);
            campaignPageListQuery.setPageSize(pageSize);
            campaignPageListQuery.setCampaignScene(CampaignSceneEnum.SECKILL_SCENE.name());
            campaignPageListQuery.setCheckStatus(CheckStatusEnum.CHECKED.getCode());
            String startTimePeriod = campaignSeckillRoundParam.getStartTimePeriod();
            String endTimePeriod = campaignSeckillRoundParam.getEndTimePeriod();

            String startTime = DateUtils.getToday();
            String endTime = DateUtils.getToday();
            if (StringUtils.isNotBlank(campaignSeckillRoundParam.getStartTime())) {
                startTime = campaignSeckillRoundParam.getStartTime();
            }
            if (StringUtils.isNotBlank(campaignSeckillRoundParam.getEndTime())) {
                endTime = campaignSeckillRoundParam.getEndTime();
            }

            String roundStartTime = startTime + " " + startTimePeriod;
            String roundEndTime = endTime + " " + endTimePeriod;
            campaignPageListQuery.setStartTime(roundStartTime);
            campaignPageListQuery.setEndTime(roundEndTime);
            if (addType == 0) {
                //手动获取
                List<CampaignSeckillManualParam> campaignManualList = campaignSeckillRoundParam.getCampaignManualList();
                if (Collections3.isEmpty(campaignManualList)) {
                    return new Page();
                }
                campaignPageListQuery.setCampaignIds(campaignManualList.stream().map(CampaignSeckillManualParam::getActivityId).collect(Collectors.toList()));
            } else {
                //自动获取
                CampaignSeckillAutoConfigParam campaignAutoConfig = campaignSeckillRoundParam.getCampaignAutoConfig();
                Integer autoType = campaignAutoConfig.getType();
                if (autoType == 0) {
                    //查询满足条件的全部活动
                    campaignPageListQuery.setCampaignStatusList(Arrays.asList(CampaignStatusEnum.NOT_STARTED.getCode(), CampaignStatusEnum.IN_PROGRESS.getCode()));
                } else {
                    String campaignStartTime = DateUtils.dayStartStr(campaignAutoConfig.getCampaignStartTime());
                    String campaignEndTime = DateUtils.dayEndStr(campaignAutoConfig.getCampaignEndTime());
                    if (StringUtils.isNotBlank(campaignStartTime) && campaignStartTime.compareTo(roundStartTime) > 0) {
                        campaignPageListQuery.setEndTime(campaignStartTime);
                    }
                    if (StringUtils.isNotBlank(campaignEndTime) && campaignEndTime.compareTo(roundEndTime) < 0) {
                        campaignPageListQuery.setEndTime(campaignEndTime);
                    }
                    campaignPageListQuery.setCampaignStatusList(campaignAutoConfig.getStatusList());
                }
            }
            ResponseResult<com.ibeeking.nematos.utils.base.Page<CampaignPageDTO>> pageResponseResult = cmsMarketingFeignCClient.queryCampaignPageList(campaignPageListQuery);
            DataUtils.falseThrowException(ResponseCodeEnum.SUCCESS.getCode().equals(pageResponseResult.getCode()), "系统异常,未查询到秒杀活动!");
            com.ibeeking.nematos.utils.base.Page<CampaignPageDTO> data = pageResponseResult.getData();
            Page<CampaignPageDTO> page = JsonUtils.fromJson(data, Page.class);
            List<CampaignPageDTO> records = JsonUtils.jsonToList(page.getRecords(), CampaignPageDTO.class);
            if (Collections3.isEmpty(records)) {
                return pageRes;
            }
            //查询商品
            List<Long> goodsIds = records.stream().filter(x -> x.getLowPriceCampaignGoodsVO() != null).map(x -> x.getLowPriceCampaignGoodsVO().getGoodsId()).collect(Collectors.toList());
            ResponseResult<List<GoodsDTO>> responseResult = cmsGoodsFeignCClient.listByGoods(goodsIds);
            List<GoodsDTO> goodsDTOS = Optional.ofNullable(responseResult).map(ResponseResult::getData).orElse(Collections3.emptyList());
            Map<Long, GoodsDTO> goodsDTOMap = goodsDTOS.stream().collect(Collectors.toMap(GoodsDTO::getId, x -> x, (o, n) -> n));

            List<PageModuleDataCommonSeckillVO> voList = new ArrayList<>();

            PageModuleDataCommonSeckillVO vo;
            for (CampaignPageDTO campaignPageDTO : records) {
                vo = new PageModuleDataCommonSeckillVO();
                vo.setId(campaignPageDTO.getId());
                vo.setActivityName(campaignPageDTO.getName());
                vo.setActivityId(campaignPageDTO.getId());
                vo.setActivityTypeName(CampaignSceneEnum.SECKILL_SCENE.getLable());
                vo.setChannel(campaignPageDTO.getChannel().get(0));
                Integer campaignStatus = campaignPageDTO.getCampaignStatus();
                vo.setStatus(campaignStatus);
                vo.setStatusDesc(campaignPageDTO.getCampaignStatusName());
                vo.setActivityValidityStart(campaignPageDTO.getStartTime());
                vo.setActivityValidityEnd(campaignPageDTO.getEndTime());
                //针对秒杀处理时间
                if (CampaignStatusEnum.NOT_STARTED.getCode().equals(campaignStatus)) {
                    //活动未开始 计算距离活动开始时间的毫秒值
                    vo.setActivityLeftTime(DateUtil.betweenMs(Calendar.getInstance().getTime(), DateUtils.parseDate(campaignPageDTO.getStartTime())));
                } else if (CampaignStatusEnum.IN_PROGRESS.getCode().equals(campaignStatus)) {
                    //活动进行中 计算距离活动场次/活动结束时间(取最近的)的毫秒值
                    String campaignEndTime = campaignPageDTO.getEndTime();
                    vo.setActivityLeftTime(DateUtil.betweenMs(Calendar.getInstance().getTime(), roundEndTime.compareTo(campaignEndTime) < 0 ? DateUtils.parseDate(roundEndTime) : DateUtils.parseDate(campaignEndTime)));
                }
                //商品活动库存
                Integer campaignGoodsDTOStock = Integer.valueOf(Optional.ofNullable(campaignPageDTO.getCampaignVO()).map(x -> x.get("effectiveStock")).orElse(0).toString());
                vo.setGoodsEffectiveStock(campaignGoodsDTOStock);
                CampaignGoodsDTO lowPriceCampaignGoodsVO = campaignPageDTO.getLowPriceCampaignGoodsVO();
                if (lowPriceCampaignGoodsVO != null) {
                    vo.setPrice(NumberUtils.cent2Yuan(lowPriceCampaignGoodsVO.getPrice()));
                    vo.setGoodsId(lowPriceCampaignGoodsVO.getGoodsId());
                    vo.setSkuId(lowPriceCampaignGoodsVO.getGoodsSkuId());
                    GoodsDTO goodsDTO = goodsDTOMap.get(lowPriceCampaignGoodsVO.getGoodsId());
                    if (goodsDTO != null) {
                        vo.setName(goodsDTO.getName());
                        vo.setRemark(goodsDTO.getRemark());
                        vo.setImgUrl(goodsDTO.getThumb());
                        vo.setMarkingPrice(NumberUtils.cent2Yuan(goodsDTO.getPrice()));
                        vo.setSaleStock(goodsDTO.getSaleStock());
                        //优惠额
                        BigDecimal preferentialPrice = NumberUtil.sub(vo.getMarkingPrice(), vo.getPrice());
                        vo.setPreferentialPrice(NumberUtil.isGreater(preferentialPrice, BigDecimal.ZERO) ? preferentialPrice : BigDecimal.ZERO);
                        if (goodsDTO.getStock() < campaignGoodsDTOStock) {
                            //商品活动库存,商品库存取小的值
                            vo.setGoodsEffectiveStock(goodsDTO.getStock());
                        }
                    }
                }
                vo.setStock(vo.getGoodsEffectiveStock());
                voList.add(vo);
            }
            pageRes = JsonUtils.fromJson(page, Page.class);
            pageRes.setRecords(voList);
        }
        return pageRes;
    }

    private PageModuleServiceImpl getBean() {
        return SpringBeanUtil.getBean(this.getClass());
    }


}
